/*基本数据类型*/
const q: string = 'hello';
const w: number = 1;
const e: boolean = true;
const r: null = null;
const t: undefined = undefined;


/*接口*/
interface IBytedancer {
    /*只读属性：约束属性不可在对象初始化外赋值*/
    readonly jobId: number;
    name: string;
    sex: 'man' | 'woman';
    age: number;
    /*可选属性：定义该属性可以不存在*/
    hobby?: string;

    /*任意属性：约束所有对象属性都必须是该属性的子类型*/
    [key: string]: any;

}

/*对象类型*/
const bytedancer: IBytedancer = {
    jobId: 9300,
    name: 'liu',
    sex: 'man',
    age: 20,
    hobby: 'swimming',
}


/*报错：无法分配到'jobId'，因为它是只读属性*/
// bytedancer.jobId = 123456;
/*成功：任意属性标注下可以添加任意属性*/
bytedancer.plateform = 'data';
/*报错：缺少属性“name”，hobby可省略*/

/*
const bytedancer2:IBytedancer ={
    jobId:89645,
    sex:"man",
    age:18
}
*/


/*函数类型*/
function add(x: number, y: number): number {
    return x + y;
}

const mult: (x: number, y: number) => number = (x, y) => x * y;

/*函数也可以使用接口定义类型*/
interface IMult {
    (x: number, y: number): number;
}

const mult2: IMult = (x, y) => x * y;



